import { httpGet, httpPut } from "@/appBase/request";
import { toData } from "@/appBase/utils";

/**
 * 省市区(地址)查询
 * parentCode
 * @param {Object} params
 * @param {String} params.parentId 
 */
export function queryRegion(params) {
    const t = parseInt(Math.random()*1000);
    return httpGet(`/area/list?_t=${t}`,params).then((result) => toData(result));
}

/**
 * 省市区树查询
 */
export function queryRegionTree(params) {
    return httpGet(`/area/tree`,params).then((result) => toData(result));
}

/**
 * 查询内容
 * @param {String} key 内容 key 
 */
export function queryContent(key) {
    const t = parseInt(Math.random()*1000);
    return httpGet(`/common/dict/item/list?dictCode=${key}&_t=${t}`).then((result) => {
        const data = toData(result);
        return {
            // 内容
            content: data,
            // 内容描述
            description: null,
            // 内容图片地址
            url: null
        }
    });
}

/**
 * 查询菜单
 */
export function queryMenus() {
    return httpGet(`/getRouters`).then(res => toData(res));
}

/**
 * 修改密码
 * @param {Object} params 
 * @param {String} params.oldPassword
 * @param {String} params.newPassword
 * @returns 
 */
export function updatePassword(params) {

    return httpPut(`/system/user/profile/updatePwd?oldPassword=${params.oldPassword}&newPassword=${params.newPassword}`).then((result) => toData(result) );
}

/**
 * 查询基础用户信息
 * @returns 
 */
export const queryBaseUserInfo = ()=>{
    return httpGet('/user/base/info').then((result) => toData(result));

}